package org.functional.demo;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Zhang Yu
 * @description: TODO
 * @date 2024/5/14 13:40
 */
public class Demo1 {

    static void interfaceDemo() {
        String[] array = new String[]{"Apple", "Orange", "Banana", "Lemon"};
        Arrays.sort(array, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        System.out.println(String.join(",", array));
    }

    static void lambdaDemo(){
        String[] array = new String[]{"Apple", "Orange", "Banana", "Lemon"};
        Arrays.sort(array, (o1, o2) -> {
            return o1.compareTo(o2);
        });
        System.out.println(String.join(",", array));
    }

    static void lambdaNewDemo(){
        String[] array = new String[]{"Apple", "Orange", "Banana", "Lemon"};
        Arrays.sort(array, Comparator.naturalOrder());
        System.out.println(String.join(",", array));
    }

    static void lambdaNew2Demo(){
        String[] array = new String[]{"Apple", "Orange", "Banana", "Lemon"};
        Arrays.sort(array, Demo1::cmp);
        System.out.println(String.join(",", array));
    }

    static int cmp(String s1, String s2) {
        return s1.compareTo(s2);
    }



    public static void main(String[] args) {
//        interfaceDemo();
//        lambdaDemo();
//        lambdaNewDemo();
        lambdaNew2Demo();
    }

}
